export declare interface instanceObject {
  [key: string]: string;
}

/**
 * JSON转url参数
 * @param data Json格式数据
 * */
export const formatJsonToUrlParams = (data: instanceObject) => {
  return typeof data === 'object'
    ? Object.keys(data)
        .map((key) => {
          return `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`;
        })
        .join('&')
    : '';
};


/**
 * 防抖
 * @param data Json格式数据
 * */
export const throttle = (callback: (v: any) => void, time: number) => {
  let timer: any = null;
  return function (v: any) {
    if(timer !== null){
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      callback(v);
    }, time * 1000);
  };
};


export default formatJsonToUrlParams;
